﻿/**
 * Copyright (C) 2004-2009 D3Systems, Inc. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA 
 */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace OMGTray
{
 
    /// <summary>
    /// OMG Tray Application that will be tasked with managing the OMG Service.
    /// </summary>
    public partial class OmgTray : Form
    {
        /// <summary>
        /// The icon reference that will be displayed in the system tray.
        /// </summary>
        private Icon mDirIcon = new Icon(typeof(OmgTray).Assembly.GetManifestResourceStream("OMGTray.Icon1.ico"));

        /// <summary>
        /// OMG Tray Constructor.
        /// </summary>
        public OmgTray()
        {
            // Initialize all the System Components
            InitializeComponent();

            // Keep the form hidden
            this.Hide();

            // Show the System Tray Icon
            InitializeNotifyIcon();
        }

        /// <summary>
        /// Method that Initializes the Notification/System Tray Application
        /// </summary>
        private void InitializeNotifyIcon()
        {
            //setup the Icon
            //NotifyIcon WSNotifyIcon = new NotifyIcon();
            notifyIcon1.Icon = mDirIcon;
            notifyIcon1.Text = "Right Click to Configure";
            notifyIcon1.Visible = true;

            //Create the MenuItem objects and add them to
            //the context menu of the NotifyIcon.
            MenuItem[] mnuItems = new MenuItem[3];

            //create the menu items array
            mnuItems[0] = new MenuItem("Hello World", new EventHandler(this.ShowMessage));
            mnuItems[0].DefaultItem = true;
            mnuItems[1] = new MenuItem("-");
            mnuItems[2] = new MenuItem("Exit", new EventHandler(this.ExitApp));
            

            //add the menu items to the context menu of the NotifyIcon
            ContextMenu notifyIconMenu = new ContextMenu(mnuItems);
            notifyIcon1.ContextMenu = notifyIconMenu;
        }

        /// <summary>
        /// Convenience EventHandler Method used to show a Message Box
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void ShowMessage(object sender, EventArgs e)
        {
            MessageBox.Show("Hello, World! " + OMGGateways.ConfigurationHandler.checkDir());
            
        }

        /// <summary>
        /// Convenience EventHandler Method for exiting the App.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void ExitApp(object sender, EventArgs e)
        {
            //Hide the NotifyIcon.
            notifyIcon1.Visible = false;

            this.Close();
        }

    }
}
